package com.woniuxy.woniuhis.service.impl;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.woniuxy.woniuhis.entity.OrderCart;
import com.woniuxy.woniuhis.exception.OrderCartServiceException;
import com.woniuxy.woniuhis.mapper.OrderCartMapper;
import com.woniuxy.woniuhis.service.OrderCartService;

@Service
public class OrderCartServiceImpl implements OrderCartService{

	@Autowired
	OrderCartMapper orderCartMapper;
	
	
	/* 
	 * 添加购物车条目的服务方法
	 */
	@Transactional  //事务
	@Override
	public void addOrderCart(OrderCart orderCart) {
		try {
			
			//从前端输入 @药物id @药物名字   @请求数量  @生产商名字 @药品进价
			orderCartMapper.insertOrderCart(orderCart);
			
		} catch (Exception e) {
			System.out.println("addOrderCart异常");
			e.printStackTrace();
			throw new OrderCartServiceException("addOrderCart异常");
		}
	}
	
	
	/* 
	 * 删除购物车条目的服务方法
	 */
	@Transactional  //事务
	@Override
	public void delOrderCart(OrderCart orderCart) {
		try {
			//前端输入 购物车id
			orderCartMapper.deleteOrderCart(orderCart);
			
		} catch (Exception e) {
			System.out.println("delOrderCart异常");
			e.printStackTrace();
			throw new OrderCartServiceException("delOrderCart异常");
		}
	}


	/* 
	 * 根据药物id找购物车条目
	 */
	@Override
	public OrderCart findOrderByMediId(OrderCart orderCart) {
		try {
			//前端输入 购物车id
			OrderCart cart = orderCartMapper.selectOrderCartByMediId(orderCart);
			return cart;
			
		} catch (Exception e) {
			System.out.println("findOrderByMediId异常");
			e.printStackTrace();
			throw new OrderCartServiceException("findOrderByMediId异常");
		}	
	}
	
	/* 
	 * 购物车增加方法
	 */
	@Override
	public void declineCartService(OrderCart orderCart) {
		try {
			
			orderCartMapper.declineCart(orderCart);
			
		} catch (Exception e) {
			System.out.println("declineCartService异常");
			e.printStackTrace();
			throw new OrderCartServiceException("declineCartService异常");
		}	
	}

	/* 
	 * 购物车增加方法
	 */
	@Override
	public void incrementCartService(OrderCart orderCart) {
		try {
			
			orderCartMapper.incrementCart(orderCart);
			
		} catch (Exception e) {
			System.out.println("incrementCartService异常");
			e.printStackTrace();
			throw new OrderCartServiceException("incrementCartService异常");
		}	
	}


	@Override
	public List<OrderCart> findAllCart() {
		try {
			
			List<OrderCart> carts = orderCartMapper.selectOrderCart();
			
			return carts;
			
		} catch (Exception e) {
			System.out.println("findAllCart异常");
			e.printStackTrace();
			throw new OrderCartServiceException("findAllCart异常");
		}
	}

	
}
